/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package converters;

import entities.Resto;
import facades.RestoFacade;
import javax.inject.Named;
import javax.enterprise.context.ApplicationScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.inject.Inject;

/**
 *
 * @author damfercer
 */
@Named("restoConverter")
@ApplicationScoped
public class RestoConverter implements Converter{
    @Inject
    private RestoFacade RestoFacade;
    /**
     * Creates a new instance of DConverter
     */
    public RestoConverter(){
    }

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        Resto Resto=null;
        try{
        Integer identificador=new Integer(value);
        Resto=RestoFacade.find(identificador);
        }
        catch(NumberFormatException e){
            
        }
        return Resto;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        String res=null;
        Resto Resto=null;
        if(value.getClass().equals(Resto.class)){
            Resto=(Resto)value;
        }
        if(Resto!=null){
            res=Resto.getIdResto().toString();
        }
        return res;
    }
}
